#include <stdio.h>
#include <stdlib.h>

int main()
{
    int* pi = (int*)malloc(20 * sizeof(int));
    if (pi == NULL)
    {
        perror("malloc");
        return 1;
    }
    int* pi2 = pi;
    for (int i = 0; i < 20; i++)
        pi[i] = i;
    
    int* q = (int*)malloc(10 * sizeof(int));
    int* tmp = (int*)realloc(pi, 10 * sizeof(int));
    if (tmp == NULL)
    {
        perror("realloc");
        return 1;
    }
    pi = tmp;
    tmp = NULL;
    if (pi)
        for (int i = 0; i < 10; i++)
            printf("%d ", pi[i]);
    printf("\n");
    free(pi);
    pi = NULL;
    free(q);
    q = NULL;

    return 0;
}